<?php
// event/Form/Event.php

class Form_Tour extends Zend_Form
{

    protected $_noDecorator = array(
        'ViewHelper', 
        'Errors'
    );

    public function cluBuild($params)
    {
    	$this->setMethod('POST');
    	
        if($params['action'] == 'new')
        {
//        	$a = $params['view']->hvnUrl(array('module' => 'tour', 'action'=>'new'));
//        	$this->setAction($a);
            $this->setAttrib('id', 'new_tour');
        } 
		elseif($params['action'] == 'edit')
		{
            $this->setAttrib('id', 'edit_tour');
//        	$a = $params['view']->hvnUrl(array('module' => 'tour', 'action'=>'edit')) . '?id='.$params['id'];
//        	$this->setAction($a);
		}
		
		$this->setAction($params['action_url']);

    	$filterHtmlBody = new Clu_Filter_HtmlBody();
		$myValidator = new Zend_Validate_Regex('/^[A-Z0-9_\s\-]*$/i'); //alpha, num, space, -, _
        $myValidator->setMessage(t(60), Zend_Validate_Regex::NOT_MATCH);
		$this->addElementPrefixPath('Clu_Filter', 'Clu/Filter/', 'filter');
		
		//tour name
        $name = new Zend_Form_Element_Text('name', 
                         array('disableLoadDefaultDecorators' => true,
                               'required'   => true,             
                               'class' => 'inputText'));
        
        $name->addDecorators($this->_noDecorator);
        	  /*->addValidator($myValidator);*/ //TODO: what is the best filter for the name??
        $this->addElement($name);
        
        //tour itinery
        $itinery = new Zend_Form_Element_Text('itinery', 
                         array('disableLoadDefaultDecorators' => true,
                               'required'   => false,             
                               'class' => 'inputText'));
        
        $itinery->addDecorators($this->_noDecorator);
        	  /*->addValidator($myValidator);*/ //TODO: what is the best filter for the name??
        $this->addElement($itinery);
        
        //add language. Only optional when creating new
        $tourLanguage = new Zend_Form_Element_Select('tour_lang',  
                         array('disableLoadDefaultDecorators' => true,
	    //				'required' => true
                         )); 
        $tourLanguage->addMultiOption('vi',t(40))
                       ->addMultiOption('en',t(41))
                       ->addMultiOption('cn',t(42))
                       ->addMultiOption('jp',t(43))
                       ->addDecorators($this->_noDecorator);
        $this->addElement($tourLanguage);
        
        //add category
        $category = new Zend_Form_Element_Select('category_tour',  
                 array('disableLoadDefaultDecorators' => true,
                 'required'   => true,  
                 ));
        
    	$mCategory = new category_Model_Category();
        $mCategory->setTables('tour');
        $category	->addMultiOption('none','---'.t(113).'---');
        foreach($mCategory->getRootType('Root_Tour') as $e) {
        	$e = (array)$e;
            $category->addMultiOption($e['id'], p($e['name']));
        }             
        $category->addDecorators($this->_noDecorator);
        $this->addElement($category);
        

		//price
        $price = new Zend_Form_Element_Text('price', 
                         array('disableLoadDefaultDecorators' => true,
                               /* 'required'   => true, */             
                               'class' => 'inputText'));
        
        $price->addDecorators($this->_noDecorator)
        	 ->addValidator($myValidator);
        $this->addElement($price);
		
		//price currency
		$price_currency = new Zend_Form_Element_Select('price_currency',  
                             array('disableLoadDefaultDecorators' => true));
        $price_currency->addMultiOption('VND',__('VND'))
            	       ->addMultiOption('USD',__('USD'))
            	       ->addMultiOption('EUR',__('EUR'))
            	       ->addMultiOption('JPY',__('JPY'))
            	       ->addMultiOption('CNY',__('CNY'));
        
        $price_currency->addDecorators($this->_noDecorator);
        $this->addElement($price_currency);
        
		//tour duration: number of days
        $duration = new Zend_Form_Element_Text('total_duration', 
                         array('disableLoadDefaultDecorators' => true,
                               /* 'required'   => true, */             
                               'class' => 'inputText'));
        
        $duration->addDecorators($this->_noDecorator)
        	 ->addValidator($myValidator);
        $this->addElement($duration);

        //add start date
        $departure_date= new Zend_Form_Element_Text('departure_date',  
                         array('disableLoadDefaultDecorators' => true,
//                                'required' => true
                         )); 
         
        $departure_date->addDecorators($this->_noDecorator);
        $departure_date->size = 10; //TODO
        $this->addElement($departure_date);

        
        //add start date
        $return_date= new Zend_Form_Element_Text('return_date',  
                         array('disableLoadDefaultDecorators' => true,
//                                'required' => true
                         )); 
         
        $return_date->addDecorators($this->_noDecorator);
        $return_date->size = 10; //TODO
        $this->addElement($return_date);
        
        //organizer info
        $organizerName = new Zend_Form_Element_Text('organizer_name', 
                         array('disableLoadDefaultDecorators' => true,
                               'required'   => true,             
                               'class' => 'inputText'));
        
        $organizerName->addDecorators($this->_noDecorator)
        	 ->addValidator($myValidator);
        $this->addElement($organizerName);

        //organizer website
        $organizerWebsite = new Zend_Form_Element_Text('organizer_website', 
                         array('disableLoadDefaultDecorators' => true,
                               /*'required'   => false,*/             
                               'class' => 'inputText'));
        
        $organizerWebsite->addDecorators($this->_noDecorator);
        	 //->addValidator($myValidator); //TODO
        $this->addElement($organizerWebsite);
		
        //organizer contact
        $fck = new Clu_Form_Element_FckEditor('organizer_contact', array(
        		'fckOptions' => array (
        						'Height' => 150,
        						'Width'  => 500,
        						'ToolbarSet' => 'UserSignature'
        					)
       			 )
        );
        $fck->setLabel(t(429));
        $fck->addFilter($filterHtmlBody ); //TODO: if our people, maybe we don't need to filter
        $this->addElement($fck);
        
        //add description $user
        $description = new Clu_Form_Element_FckEditor('description', array(
        		'fckOptions' => array (
        						'Height' => 600,
        						'Width'  => 600,
        						'ToolbarSet' => 'Full'
        					)
       			 )
        );
        $description->setLabel(t(21));

        //if our people, maybe we don't need to filter
		if (strpos ($params['userPermissions'], 'set status tour'))
		{
        	$description->addFilter($filterHtmlBody ); 
		}
		
        $this->addElement($description);

        if ($params['action'] === 'new' && (strpos ($params['userPermissions'], 'set status tour') === false))
		{
            //add check captcha
            $elementCaptcha = 
            				   new Zend_Form_Element_Captcha('captcha_newtour',
                               array('captcha' => 'Image','captchaOptions' =>
                               array(
                                    'captcha' => 'Image',
                                    'wordLen' => 4,
                                    'timeout' => 300,
                                    'imgDir'  =>APP_PATH.'/public/captcha',
                                    'imgUrl' => '/public/captcha/',
                                    'width' => 175,
                                    'height' => 60,
                                    'font' => APP_PATH.'/public/captcha/font/tahoma.ttf',
                                    'DotNoiseLevel' => 10,  
                                    'LineNoiseLevel' => 1,
                                    'expiration' => 3,
                                    'gcFreq' => 1))
            );
            $elementCaptcha->setLabel(t(39).':')
                           ->setAttrib('id','captcha_neweventImage')
                       	   ->setRequired(true);
            $this->addElement($elementCaptcha);
		}    

        //status
        //only the user with permission can set the status of the tour.
        //else, it will be null and default values 'queued' will be inserted to DB
        if (strpos ($params['userPermissions'], 'set status tour'))
        {
            $status = new Zend_Form_Element_Select('status',  
                             array('disableLoadDefaultDecorators' => true));
            $status->addMultiOption('featured',t(33))
            	   ->addMultiOption('published',t(34))
                   ->addMultiOption('queued',t(35))
                   ->addMultiOption('unpublished',t(36))
                   ->addMultiOption('deleted',t(37))
                   ->addDecorators($this->_noDecorator);
    		$status->setValue('published');
            $this->addElement($status);
        }        
		
        //add category
        $category = new Zend_Form_Element_Select('category_tour',  
                 array('disableLoadDefaultDecorators' => true,
                 'required'   => true,  
                 ));
        $category->addDecorators($this->_noDecorator)
        					->addMultiOption('none','---'.t(113).'---')
                           ->addMultiOption('12',t(108))
               				->addMultiOption('3',t(109));
        $this->addElement($category);
        	
        // add the submit button
		if ($params['action'] === 'new')
    		$submit = new Zend_Form_Element_Submit('submit', array('disableLoadDefaultDecorators' => true, 
                                                           'label' => t(58) ));
      	else
      	$submit = new Zend_Form_Element_Submit('submit', array('disableLoadDefaultDecorators' => true, 
                                                               'label' => t(59) ));
        
        $submit->addDecorators($this->_noDecorator);
        $this->addElement($submit);
    }
}

	/*
		áàảãạăắằẳẵặâấầẩẫậÁÀẢÃẠ 
                    'Ă'=>'A', 'Ắ'=>'A','Ằ'=>'A','Ẳ'=>'A','Ẵ'=>'A','Ặ'=>'A',         
                    'Â'=>'A', 'Ấ'=>'A','Ầ'=>'A','Ẩ'=>'A','Ẫ'=>'A','Ậ'=>'A',
                              'đ'=>'d','Đ'=>'D',
                              'é'=>'e','è'=>'e','ẻ'=>'e','ẽ'=>'e','ẹ'=>'e',
                    'ê'=>'e', 'ế'=>'e','ề'=>'e','ể'=>'e','ễ'=>'e','ệ'=>'e',
                              'É'=>'E','È'=>'E','Ẻ'=>'E','Ẽ'=>'E','Ẹ'=>'E', 
                    'Ê'=>'E', 'Ế'=>'E','Ề'=>'E','Ể'=>'E','Ễ'=>'E','Ệ'=>'E',
                              'í'=>'i','ì'=>'i','ỉ'=>'i','ĩ'=>'i','ị'=>'i', 
                              'Í'=>'I','ì'=>'I','Ỉ'=>'I','ĩ'=>'I','ị'=>'I', 
                              'ó'=>'o','ò'=>'o','ỏ'=>'o','õ'=>'o','ọ'=>'o', 
                    'ô'=>'o', 'ố'=>'o','ồ'=>'o','ổ'=>'o','ỗ'=>'o','ộ'=>'o',         
                    'ơ'=>'o', 'ớ'=>'o','ờ'=>'o','ở'=>'o','ỡ'=>'o','ợ'=>'o',         
                              'Ó'=>'O','Ò'=>'O','Ỏ'=>'O','Õ'=>'O','Ọ'=>'O', 
                    'Ô'=>'O', 'Ố'=>'O','Ồ'=>'O','Ổ'=>'O','Ỗ'=>'O','Ộ'=>'O', 
                    'Ơ'=>'O', 'Ớ'=>'O','Ờ'=>'O','Ở'=>'O','Ỡ'=>'O','Ợ'=>'O',         
                              'ú'=>'u','ù'=>'u','ủ'=>'u','ũ'=>'u','ụ'=>'u', 
                    'ư'=>'u', 'ứ'=>'u','ừ'=>'u','ử'=>'u','ữ'=>'u','ự'=>'u', 
                              'Ú'=>'U','Ù'=>'U','Ủ'=>'U','Ũ'=>'U','Ụ'=>'U', 
                    'Ư'=>'U', 'Ứ'=>'U','Ừ'=>'U','Ử'=>'U','Ữ'=>'U','Ự'=>'U', 
                              'ý'=>'y','ỳ'=>'y','ỷ'=>'y','ỹ'=>'y','ỵ'=>'y', 
                              'Ý'=>'Y','Ỳ'=>'Y','Ỷ'=>'Y','Ỹ'=>'Y','Ỵ'=>'Y' );
		*/

?>